package com.kecheng.dao;

import com.kecheng.hibernate.BaseDao;
import com.kecheng.pojo.Skuclassify1;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import java.util.List;
@Component
public class Skuclassify1Dao extends BaseDao{

	public List<Skuclassify1> findall() {
		List<Skuclassify1> skuclassify1s= (List<Skuclassify1>) this.getHibernateTemplate().find("from Skuclassify1");
		return skuclassify1s;
	}

	public Skuclassify1 findById(int id) {
		List<Skuclassify1> skuclassify1s= (List<Skuclassify1>) this.getHibernateTemplate().find("from Skuclassify1 where id = ?",id);
		if(skuclassify1s.size()>0){
			Skuclassify1 Skuclassify1=skuclassify1s.get(0);
			return Skuclassify1;
		}
		return null;
	}

	public List<Skuclassify1> findmh(String name) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria=DetachedCriteria.forClass(Skuclassify1.class);
		criteria.add(
				Restrictions.ilike("name", name, MatchMode.ANYWHERE));	
		criteria.addOrder(Order.desc("id"));
		List<Skuclassify1> skuclassify1s= (List<Skuclassify1>) this.getHibernateTemplate().findByCriteria(criteria);
		return skuclassify1s;
	}

}
